package ch1strings;

public class Ex5 {

	static String replaceSpaces(String input) {
		char[] arr = input.toCharArray();
		int count = 0;
		for (char c : arr) {
			if (c == ' ') {
				count++;
			}
		}
		
		int newCount = arr.length + 2*count;
		char [] newArr = new char [newCount];
		count = arr.length - 1;
		while (newCount > 0) {
			if (arr[count] == ' ') {
				newArr[--newCount] = '0';
				newArr[--newCount] = '2';
				newArr[--newCount] = '%';
			}
			else {
				newArr[--newCount] = arr[count];
			}
			count--;
		}
		return new String(newArr);
	}

	public static void main(String ...strings) {
		String string = replaceSpaces("a b c 1");
		int a=0;
	}
	
}
